#pragma comment(linker, "/STACK:10000000")
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <set>
#include <map>
#include <cstdio>
#include <cassert>
#include <string>
#include <cstring>
#define ldb long double
#define LL long long
#define fi first
#define se second
#define fill(a, c) memset(a, c, sizeof(a))
#define sqr(a) ((a) * (a))
#define nextLine() {int c = 0; while((c = getchar()) != 10 && c != EOF);}
#define getBit(mask, k) (((mask) / pw[k]) % pw[1])
#define setBit(mask, k, l) (((mask) / pw[k + 1] * pw[1] + (l)) * pw[k] + ((mask) % pw[k]))
#define debug(a) cerr << #a << " = " << a << " ";
#define debugl(a) cerr << #a << " = " << a << "\n";
#define mp(a, b) make_pair(a, b)
#define pb(a) push_back(a)
#define ff first
#define ss second 
const ldb LDINF = 9128739847123.00;
const ldb eps = 1e-9;
const int inf = 1 << 28;
const ldb pi = fabsl(atan2l(0.0, -1.0));
using namespace std;

int n, m;
int a[200][200];
int dp[152][152][2];
int mx[210], mn[210];
int last_row = -1;


void load()
{
	cin >> n >> m;
	nextLine();
	for (int i = 0; i < n; i++)
	{
		mx[i] = 0;
		mn[i] = m - 1;
		for (int j = 0; j < m; j++)
		{
			a[i][j] = getchar();
			if (a[i][j] == 'W')
			{
				mx[i] = max(mx[i], j);
				mn[i] = min(mn[i], j);
				last_row = i;
			}
		}
		nextLine();
	}
	last_row++;
}

bool can(int i, int j, int k)
{
	if (k == 0 && j > mn[i]) return false;
	if (k == 1 && j < mx[i]) return false;
	return true;
}

int f(int i, int j, int k)
{
	if (i == last_row)
		return 0;
	if (dp[i][j][k] != -1) return dp[i][j][k];
	dp[i][j][k] = inf;
	if (can(i, j, k))
	{
		if (k == 0)
			for (int l = mx[i]; l < m; l++)
				dp[i][j][k] = min(dp[i][j][k], f(i + 1, l, k ^ 1) + abs(l - j) + 1);
		else if (k == 1)
			for (int l = 0; l <= mn[i]; l++)
				dp[i][j][k] = min(dp[i][j][k], f(i + 1, l, k ^ 1) + abs(l - j) + 1);
	}
	return dp[i][j][k];
}

void solve()
{
	memset(dp, -1, sizeof dp);
	int r = f(0, 0, 0);
	if (r == 0) cout << r;
	else cout << r - 1;
}

#define file "b"
int main()
{
	#ifndef ONLINE_JUDGE
		freopen(file".in", "rt", stdin);
		freopen(file".out", "wt", stdout);
	#endif
	load();
	solve();
	return 0;
}
